Reverse Linked ListCode CrazeMar 11, 20231 min read#include <stdio.h>#include <stdlib.h>struct node{ int data; struct node *next;};struct node *head,*newnode,*prevnode,*nextnode;int choice;void main() { printf("\n----Insertion At Beginning----"); struct node *temp; do { newnode = (struct node *)malloc(sizeof(struct node)); printf("\nEnter data : "); scanf("%d",&newnode->data); newnode->next=head; head=newnode; printf("\nEnter your choice : (0/1) "); scanf("%d",&choice); }while(choice); temp=head; printf("\n"); while(temp!=0) { printf("--%d",temp->data); temp=temp->next; } printf("\n\n"); prevnode=0,temp=nextnode=head; while(nextnode!=0) { nextnode=nextnode->next; temp->next=prevnode; prevnode=temp; temp=nextnode; } head=prevnode; temp=head; printf("\n"); while(temp!=0) { printf("--%d",temp->data); temp=temp->next; }}
#include <stdio.h>#include <stdlib.h>struct node{ int data; struct node *next;};struct node *head,*newnode,*prevnode,*nextnode;int choice;void main() { printf("\n----Insertion At Beginning----"); struct node *temp; do { newnode = (struct node *)malloc(sizeof(struct node)); printf("\nEnter data : "); scanf("%d",&newnode->data); newnode->next=head; head=newnode; printf("\nEnter your choice : (0/1) "); scanf("%d",&choice); }while(choice); temp=head; printf("\n"); while(temp!=0) { printf("--%d",temp->data); temp=temp->next; } printf("\n\n"); prevnode=0,temp=nextnode=head; while(nextnode!=0) { nextnode=nextnode->next; temp->next=prevnode; prevnode=temp; temp=nextnode; } head=prevnode; temp=head; printf("\n"); while(temp!=0) { printf("--%d",temp->data); temp=temp->next; }}
Stack Using QueueA stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...
Comments