#include<stdio.h> struct node { int item; struct node *next; }*temp,*start=NULL,*new1; void add(void); void reverse (void); void print (void); main () { int n; clrscr(); while (1) { printf ("enter choice \n1.)add 2.)reverse 3.)print 4.)exit "); scanf ("%d",&n); if (n==1) add(); if (n==2) reverse(); if (n==3) print(); if (n==4) exit(1); }
getch(); } void add(void) { int n; char ch='y'; while (ch=='y'||ch=='Y') { new1=(struct node *)malloc (sizeof (struct node)); printf ("enter number "); scanf("%d",&n); new1->item=n; new1->next=NULL; if (start==NULL) { start=new1; temp=new1; } else { temp->next=new1; temp=temp->next; } printf ("do u want to continue"); fflush(stdin); scanf ("%c",&ch);
} } void reverse (void) { int arr[10],arr1[10],i=0,k=0,l=0; for (temp=start;temp!=NULL;temp=temp->next) { arr[i]=temp->item; i++; l++; } printf ("%d",l); for (i=l-1;i>=0;i--) { arr1[k]=arr[i]; k++; } k=0; for (temp=start;temp!=NULL;temp=temp->next) { temp->item=arr1[k]; k++; } } void print (void) {
temp=start; while (temp!=NULL) { printf ("%d",temp->item); temp=temp->next; } }
#include<stdio.h> # define MAX 4 int arr[MAX],front=-1,rear=-1,q; void add(void); int delete (void); void show (void); main () { int i,n,b; clrscr(); while (1) { printf ("1.)add 2.)delete 3.)show 4.)exit");
scanf ("%d",&n); if (n==1) { add(); } if (n==2) { b=delete(); printf ("deleted item=%d",b); } if (n==3) show(); if (n==4) exit(1); } getch(); } void add(void) { int n; if (front==0 && rear==MAX-1) { printf ("queue is full"); } if (rear+1==front) {
printf ("queue is full"); } else { if (front>0) { if (rear==MAX-1) { rear=-1; } rear++; printf ("enter number"); scanf ("%d",&n); arr[rear]=n; } } if ((front==-1) && (rear!=MAX-1)||(front==0) && (rear!=MAX-1)) { rear++; printf ("enteR number"); scanf ("%d",&n); arr[rear]=n; if (front==-1) front=0; } }
int delete (void) { int data; if (front==-1) { printf ("queue is empty"); } else { data=arr[front]; printf ("delete front=%d",front); front=front+1; } return data; } void show (void) { int i; for (i=front;i<MAX;i++) { printf ("\n%d",arr[i]); } }
#include<stdio.h> void create(void); void print (void); void add(void); void addb(void); void del(void); void delb (void); void count (void); void sort (void); struct node { struct node *pre; int item; struct node *next; }*temp,*start=NULL,*new,*old=NULL; main() { int n; clrscr(); while (1) { printf ("1.)create2.)print3.)add4.)addb 5.)del 6.)delb 7.)count 8.)sort 9.)exit"); scanf ("%d",&n);
if (n==1) create(); if (n==2) print(); if(n==3) add(); if (n==4) addb(); if (n==5) del(); if (n==6) delb(); if (n==7) count(); if (n==8) sort(); if (n==9) exit(); } getch(); } void create(void) { int info; char ch='y'; while (ch=='y'||ch=='Y')
{ printf ("enter the number "); scanf ("%d",&info); new=(struct node*)malloc(sizeof(struct node)); new->pre =temp; new->item=info; new->next=NULL; if (start==NULL) { start=new; temp=new; } else { temp->next=new; temp=temp->next; } printf ("do u want to continue"); fflush(stdin); scanf ("%c",&ch); } } void print(void) { temp=start; while (temp!=NULL)
{ printf ("%d",temp->item); temp=temp->next; } } void add(void) { int n,info; printf ("enter the poistion"); scanf ("%d",&n); printf ("enter number "); scanf ("%d",&info); temp=start; while (temp!=NULL) { if (temp->item==n) { old=temp->next; new=(struct node *)malloc (sizeof(struct node)); new->pre=temp; new->item=info; temp->next=new; new->next=old; old->pre=new; } temp=temp->next;
} } void addb (void) { int n; temp=start; printf ("enter number"); scanf ("%d",&n); new=(struct node *) malloc(sizeof(struct node)); new->pre=NULL ; new->item=n; new->next= start; temp=temp->next; temp->pre=new; start=new; } void del (void) { int n; struct node *q; printf ("enter a poistion which u want to delete"); scanf ("%d",&n); temp=start; while (temp!=NULL) { if (temp->next->item==n)
{ q=temp->next; old=temp->next->next; temp->next=old; temp=temp->next; temp->pre=q->pre; free(q); } temp=temp->next; } } void delb (void) { temp=start; old=temp; temp=temp->next; temp->pre=NULL; start=temp; free(old); } void count (void) { int l=0; temp=start; while (temp!=NULL) {
l++; temp=temp->next; } printf ("\n number of node = %d",l); } void sort (void) { int t; struct node *p,*q; temp=start; for (p= temp->next;p!=NULL;p=p->next) { for (q=start;q!=NULL;q=q->next) { if ( p->item >q->item) { t=p->item; p->item=q->item; q->item=t; } } } }
#include<stdio.h> void create(void); void print (void); void insert(void); void delete(void); void insertb(void); void deleteb(void); void sort (void); struct node { int item; struct node *next; }*temp,*new,*start=NULL,*old; main () { int n; clrscr(); clrscr(); while (1) { printf ("1.)create2.)print 3.)insert4.)delete5.)insertb 6.)deleteb 7.)sort 8.)exit"); scanf ("%d",&n); if(n==1) create(); if (n==2)
print(); if(n==3) insert(); if(n==4) delete(); if (n==5) insertb(); if (n==6) deleteb(); if (n==7) sort(); if (n==8) exit(1); } getch(); } void create (void) { int info; char ch='y'; while (ch=='y'||ch=='Y') { printf ("enter number "); scanf ("%d",&info); new=(struct node*)malloc(sizeof(int)); new->item=info;
if(start==NULL) { start=new; } else { temp->next=new; } temp=new; temp->next=start; printf ("do u wan to continue"); fflush(stdin); scanf ("%c",&ch); } } void print (void) { struct node *p=NULL; temp=start; while (temp!=p) { printf ("\n%d",temp->item); p=start; temp=temp->next; } }
void insertb(void) { int info; struct node *p=NULL; printf ("enter number"); scanf ("%d",&info); new=(struct node*) malloc(sizeof(struct node)); new->item=info; new->next=start; old=start; start=new; temp=old; while (temp!=p) { if(temp->next==old) { temp->next=new; } p=start; temp=temp->next; } } void delete(void) { int n; struct node *p=NULL;
struct node *q; temp=start; printf ("\n enter number which you want to delete"); scanf ("%d",&n); while (temp!=p) { if (temp->next->item==n) { old=temp->next->next; q=temp->next; temp->next=old; free(q); } p=start; temp=temp->next; } }
void insert(void) { int info,n; struct node *p=NULL; printf ("enter number "); scanf ("%d",&info); printf ("enter poistion after u want to insert"); scanf ("%d",&n);
new=(struct node *)malloc (sizeof (struct node)); new->item=info; temp=start; while (temp!=p) { if (temp->item==n) { old= temp->next; temp->next=new; temp=temp->next; temp->next=old; } p=start; temp=temp->next; } } void deleteb(void) { struct node *p=NULL; temp=start; old=temp; start=temp->next; temp=start; while(temp!=p) { if (temp->next==old)
{ temp->next=start; temp=temp->next; } p=start; temp=temp->next; } free(old); } void sort (void) { int t; struct node *p=NULL,*x,*y; temp=start; for (x=start;x!=p;x=x->next) { for (y=x->next;y!=p;y=y->next) { if (x->item > y->item) { t=x->item; x->item=y->item; y->item=t; } p=start; }
} }