View Single Post
Old 11-08-06, 10:21 AM   #2 (permalink)
gobicse
Member
 
Join Date: Aug 2006
Age: 24
Posts: 34
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 4 gobicse is on a distinguished road
Re: Linked list ..help

//Program for linked list

#include
#define TRUE 1

struct node{
int info;
struct node *next;
};

typedef struct node *nodeptr;
nodeptr p,tp;

void startlist() {
int x;
p= getnode();
tp = p;
printf("Enter an item to insert:");
scanf("%d",&x);
p->info = x;
p->next = NULL;
}

void showlist() {
p = tp;
printf("node(p)\t Info\t Next");
while(p!= NULL) {
printf("\n %d \t%d \t%d ",p,p->info,p->next);
p=p->next;
}
putchar('\n');
}

void insafter(noteptr p,int x) {
nodeptr a;
if(p==NULL) {
printf("void insertion");
exit(1);
}
q= getnode();
q->info = x;
q->next = p->next;
p->next = q;
}

nodeptr getnode() {
nodeptr p;
p =(nodeptr) malloc(sizeof(struct node));
return(p);
}

void freenode(nodeptr p) {
free(p);
}

void deleteafter(nodeptr p) {
nodeptr q;
if(p==NULL ::q->next ==NULL) {
printf("void deletion");
exit(1);
}
q=q->next;
p->next = q->next;
freenode(q);
}

void main() {
int choice,i,x;
nodeptr n;
nodeptr getnode();
clrscr();
printf("\n Enter Ur choice 1-> start 2->showlist 3->insert 4->delete 5->end \n");
while (TRUE) {
printf("Enter ur choice");
scanf("%d",&choice);
switch(choice) {
case 1: startlist(); break;
case 2: showlist(); break;
case 3: printf ("Node Insertion: after which node?:");
scanf("%d",&n);
p=n;
printf("Enter the item for insertion:");
scanf("%d",&x);
insafter(p,x);
break;
case 4: printf("Node deletion:After which node?:");
scanf("%d",&n); p=n;
delafter(p);break;
case 5: exit(5);
}
}
}
gobicse is offline Offline   Reply With Quote
 
45,000 Jobs - Get an Interview Call,  Post Your Resume Here