Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program to implement stack using linked list.
- #include<stdio.h>
- #include<conio.h>
- #include<malloc.h>
- struct node {
- int t_no;
- char p_name[50];
- struct node *link;
- } *temp = NULL, *top = NULL;
- void insert() {
- clrscr();
- temp = (struct node *) malloc(sizeof(struct node));
- printf("\n Enter ticket no. : ");
- scanf("%d", &temp->t_no);
- printf(" Enter passenger name: ");
- scanf("%s", &temp->p_name);
- temp->link = top;
- top = temp;
- printf("\n Insert Successful!");
- printf("\n Press any key to continue...");
- getch();
- }
- void display() {
- clrscr();
- if (top == NULL) {
- printf("\n The stack is empty!");
- } else {
- temp = top;
- while (temp != NULL) {
- printf("\n Ticket no. : %d", temp->t_no);
- printf("\n Passenger name: ");
- puts(temp->p_name);
- temp = temp->link;
- }
- }
- printf("\n Press any key to continue...");
- getch();
- }
- void delete_node() {
- clrscr();
- if (top == NULL) {
- printf("\n The stack is empty!");
- } else {
- temp = top;
- top = top->link;
- printf("\n Deleted the following record: ");
- printf("\n Ticket no. : %d", temp->t_no);
- printf("\n Passenger name: ");
- puts(temp->p_name);
- free(temp);
- }
- printf("\n Press any key to continue...");
- getch();
- }
- void main()
- {
- int choice;
- clrscr();
- while(1) {
- clrscr();
- printf("\n\t\t\tMain Menu\n\t1.Insert\n\t2.Display\n\t3.Delete\n\t4.Exit");
- printf("\n Enter your choice: ");
- scanf("%d", &choice);
- switch(choice) {
- case 1:
- insert();
- break;
- case 2:
- display();
- break;
- case 3:
- delete_node();
- break;
- case 4:
- return;
- }
- }
- }
- //Program to implement queue using linked list.
- #include<conio.h>
- #include<stdio.h>
- #include<malloc.h>
- struct node {
- int t_no;
- char p_name[50];
- struct node *link;
- } *temp=NULL, *front=NULL, *rear=NULL;
- void insert() {
- clrscr();
- temp = (struct node *) malloc(sizeof(struct node));
- printf("\n Enter ticket no.: ");
- scanf("%d", &temp->t_no);
- printf("\n Enter passenger name: ");
- scanf("%s", &temp->p_name);
- temp->link = NULL;
- if (front == NULL) {
- front = temp;
- rear = temp;
- } else {
- rear->link = temp;
- rear = temp;
- }
- printf("\n Insert Successful!");
- printf("\n Press any key to continue...");
- getch();
- }
- void display() {
- clrscr();
- if (front == NULL) {
- printf("\n The queue is empty!");
- } else {
- temp = front;
- while (temp != NULL) {
- printf("\n Ticket no. : %d", temp->t_no);
- printf("\n Passenger name: ");
- puts(temp->p_name);
- temp = temp->link;
- }
- }
- printf("\n Press any key to continue...");
- getch();
- }
- void delete_node() {
- clrscr();
- if (front == NULL) {
- printf("\n The queue is empty!");
- } else {
- temp = front;
- front = front->link;
- printf("\n Deleted the following record: ");
- printf("\n Ticket no. : %d", temp->t_no);
- printf("\n Passenger name: ");
- puts(temp->p_name);
- free(temp);
- }
- printf("\n Press any key to continue...");
- getch();
- }
- void main()
- {
- int choice;
- clrscr();
- while(1) {
- clrscr();
- printf("\n\t\t\tMain Menu\n\t1.Insert\n\t2.Display\n\t3.Delete\n\t4.Exit");
- printf("\n Enter your choice: ");
- scanf("%d", &choice);
- switch(choice) {
- case 1:
- insert();
- break;
- case 2:
- display();
- break;
- case 3:
- delete_node();
- break;
- case 4:
- return;
- }
- }
- }
Add Comment
Please, Sign In to add comment