Posts

Showing posts with the label Linked List Using C

Stack Implementation Using Linked-List

Image
The stack implementation using the linked list. Advantages: Always takes constant time to push and pop the elements Can grow to infinite size Disadvantages: More time take to find the k th element in the list Require more memory storage for each data element Implementation of Stack using the Linked List First step is to define the node structure Variable name called TOP for indexing  Check the condition for Empty and Full of the list Make a function to display the List elements Make a function for PUSH and POP operation #include #include struct node { int data; struct node *next; }*top=NULL; void push() { int n; struct node *newNode; newNode=(struct node*)malloc(sizeof(struct node)); printf("enter the data\n"); scanf("%d",&n); newNode->data=n; if (top==NULL) newNode->next=NULL; else newNode->next=top; top=newNode; printf("insert is sucessfull"); } void pop() { if (top==NULL) printf(...