





















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















































Nod1.item Node1.next
Node2.item Node2.next
node
node
Node1 can be attached with node as Node1.next=&node
Node1.item Node1.next
node
Node2.item Node.next
node
Node2.next =^ Node1.item = Node2.item=
(^) Circular list (^) Given a pointer p to a node in a linear linked list we can not reach any of the nodes that precede node (p). (^) So if the next field of last node is changed to point back to the first node rather than null ptr, such a list is called circular list. (^) Now in it it is possible to reach any other point in the list. (^) However see the difficulty to add a node in the beginning or at the end.
(^) Cin>>N; (^) If(N<=0) { Cout<<“\n error”; Return();} (^) First = new stud; (^) Cout<<“\n enter data”; (^) Cin>>first->name>>first->rollno; (^) First->next = NULL; Last =first; For(I=1;I<n;I++) {X= new stud; (^) Cout<<“\n Entere data”; (^) Cin>>x->name>>x->rollno; (^) X->next = NULL; (^) Last->next = x; Last = x; } }
(^) For reversing the list (^) Node reverse(list) (^) { (^) Nodeback, ahead, ptr; (^) If(list==NULL) (^) { (^) cout<<“\n error”; (^) return(list); (^) } (^) ptr = list; (^) Back = list;
(^) We can construct a class of linked list
(^) Class link-list
(^) {
(^) Struct stud
(^) { char name[15];
(^) Int rollno;
(^) Stud*next;
(^) };
(^) Stud first,last,x;
(^) Int I,n;
(^) Public:
(^) Linked-list()
(^) {first = last = x = NULL;}
(^) Header lists are generally organized in the form
of circular lists. The advantage of header lists is that all link pointers contain valid addresses. (^) Void create();
(^) Void traverse();
(^) };
Stack
It is defined as a list in which all insertions and deletions are made at one end,called to of the stack. Stack is a linear data structure with a variable size in the sense that the stack size depends upon the number of items currently present in it. With additions and deletions the size of the stack changes therefore it is a dynamic data structure. Stack operations Push- when an item is added Pop- when an item is deleted