Slip 1_1: .Implement a list library (doublylist.h) for a doubly linked list of integers with the create, display operations. Write a menu driven program to call these operations.

 Header File : doublylist.h

#include<stdio.h>
#include<stdlib.h>
struct node
{
 struct node *prev;
 int data;
 struct node *next;
};
struct node *f;
void create()
{
 int n,i;
 struct node *s;
 printf("enter number of nodes needed : ");
 scanf("%d",&n);
 f=(struct node *)malloc(sizeof(struct node));
 printf("enter data : ");
 scanf("%d",&f->data);
 f->prev=NULL;
 s=f;
 for(i=1;i<n;i++)
 {
 s->next=(struct node *)malloc(sizeof(struct node));
 s=s->next;
 printf("enter data :");
 scanf("%d",&s->data);
 }
 s->next= NULL;
}
void display()
{
 struct node *s;
 for(s=f;s!=NULL;s=s->next)
 {
 printf(" %d -> ",s->data);
 }
}
Program File
#include <stdio.h>
#include "doublylist.h"
int main()
{ int ch;
 do
 {
 printf("\n1.create\n2.display\n0.exit");
 printf("enter choice :");
 scanf("%d",&ch);
 switch (ch)
 {
 case 1: create();
 break;
 case 2: display();
 break;
 case 0: break;
 default:
 default:printf("invalid choice ");
 break;
 }
 }while(ch!=0);
}
x

Comments

Popular posts from this blog

Slip 22_2: Read the data from file 'cities.txt' containing names of cities and their STD codes. Accept a name of the city from user and use sentinel linear search algorithm to check whether the name is present in the file and output the STD code, otherwise output “city not in the list”. Solution :

Slip10_2, 30_1 : Read the data from the file “employee.txt” and sort on names in alphabetical order (use strcmp) using bubble sort or selection sort

Slip 10_1 ,22_1: Implement a linear queue library (st_queue.h) of integers using a static implementation of the queue and implementing the init(Q), add(Q) and peek(Q) operations. Write a program that includes queue library and calls different queue operations