1 solutions
-
0
C :
#include<stdio.h> #include<stdlib.h> typedef struct tagNODE { int data; struct tagNODE *next; }node,*linklist; void linkcreat(linklist *head) { linklist temp,upd; int buffer; (*head)=(linklist)malloc(sizeof(node)); (*head)->next=NULL; upd=(*head); scanf("%d",&buffer); while(buffer>0) { temp=(linklist)malloc(sizeof(node)); temp->next=NULL; upd->next=temp; temp->data=buffer; upd=temp; scanf("%d",&buffer); } } void linkdelet(linklist head,int x) { linklist temp,val; temp=head; while(temp->next!=NULL) { if(temp->next->data>x) { val=temp->next; temp->next=temp->next->next; free(val); val=NULL; continue; } if(temp->next!=NULL) temp=temp->next; } } void linkput(linklist head) { linklist temp; temp=head; while(temp->next!=NULL) { temp=temp->next; printf("%d ",temp->data); } } int main() { int x; linklist temp,head; linkcreat(&head); scanf("%d",&x); linkdelet(head,x); linkput(head); return 0; }
C++ :
#include<bits/stdc++.h> using namespace std; struct node{ int data; node *next; }; void Print(node *h){ node *x = h->next; while(x!=NULL){ cout<<x->data<<" "; x = x->next; } } void Delete(node *h,int val){ node *x = h,*y; while(x!=NULL){ if(x->next!=NULL&&x->next->data>val){ y = x->next; x->next = y->next; delete y; } else{ x = x->next; } } } int main() { node *h,*p,*r; h = new node; h->next = NULL; r = h; int x; while(cin>>x&&x!=-1){ p = new node; p->data = x; p->next = NULL; r->next = p; r = p; } cin>>x; Delete(h,x); Print(h); return 0; }
Pascal :
program p26753; type pointer=^rec; rec=record data:longint; next:pointer; end; var head,p,q:pointer; i,x,n:longint; begin head:=nil; read(n); while n>=0 do begin if head=nil then begin new(p); p^.data:=n; p^.next:=nil; q:=p; head:=p; end else begin new(p); p^.data:=n; p^.next:=nil; q^.next:=p; q:=p; end; read(n); end; q:=head; read(x); while q<>nil do begin if q^.data<=x then write(q^.data,' '); q:=q^.next; end; end.
- 1
Information
- ID
- 511
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By