EmbLogic's Blog

program for stack using link list

head 1.5;
access;
symbols;
locks
root:1.5; strict;
comment @ * @;

1.5
date 2014.07.17.03.57.50; author root; state Exp;
branches;
next 1.4;

1.4
date 2014.07.16.13.55.28; author root; state Exp;
branches;
next 1.3;

1.3
date 2014.07.16.13.52.30; author root; state Exp;
branches;
next 1.2;

1.2
date 2014.07.16.13.48.56; author root; state Exp;
branches;
next 1.1;

1.1
date 2014.07.16.13.04.04; author root; state Exp;
branches;
next ;

desc
@created main menu and give the choice
declare structure in which one data is info and another is next pointer
of structure type
set the top pointr to -1
@

1.5
log
@*** empty log message ***
@
text
@#include
#include
static int top=-1;
int size;
struct link
{
int info;
struct link *next;
};
struct link *create_node()
{
struct link *temp;
top++;
temp=(struct link *)malloc(sizeof(struct link));
printf(“please enter data :\n”);
scanf(“%d”,&temp->info);

temp->next=NULL;
return temp;

}
struct link *push(struct link *temp)
{
struct link *push=temp;

while(push->next!=NULL)
{
push=push->next;
}
push->next=create_node();
push=push->next;

}
pop(struct link *temp)
{
struct link *temp1=temp->next;
/*while(temp1)
{
temp->info=temp1->info;
if(temp1->next==NULL)
{

temp->next=NULL;
free(temp1);
break;

}
else
{ temp=temp1;
temp1=temp->next;
} }
// temp=NULL;*/
while(temp->next)
{
temp1=temp->next;
if(temp1->next==NULL)
{
temp->next=NULL;
free(temp1);
break;
}
temp=temp->next;

}
top–;
}

display(struct link *disp)
{
printf(“\n stack is :\n”);
while(disp)
{
printf(“%d \n”,disp->info);
disp=disp->next;
}

}
getchoice(int choice)
{
static int flag=0;
static struct link *start,*new;
switch(choice)
{
case 1:
if(top==-1 )
{
start=new=create_node();
flag=1;
}
else
printf(“push the data stack is already created\n”);
break;

case 2:if(top<size-1 && flag)
{
push(new);
}
else if(top-1)
pop(start);
else
printf(“stack is empty\n”);
break;
case 4:
if(top>-1)
display(start);
else
printf(“create stack first \n”);
break;
case 0:
exit(0);
break;
default:
printf(“enter right choice !!\n”);
}
return 0;
}

int main()
{
int choice;
printf(“enter the size of stack \n”);
scanf(“%d”,&size);
while(1)
{
printf(“____MAIN MENU___\n”);
printf(“____1.CREATE STACK__\n”);
printf(“____2.PUSH _____\n”);
printf(“____3.POP _____\n”);
printf(“____4.DISPLAY ____\n”);
printf(“____0.EXIT _____\n”);
printf(“enter choice :\n”);
scanf(“%d”,&choice);
getchoice(choice);
}
return 0;
}
@

1.4
log
@remove error
@
text
@d15 2
a16 1

a24 9
int flag=0;
if(top==0&& !flag)
{
printf(“enter data :\n”);
scanf(“%d”,&push->info);
flag=1;
}
else
{
d26 1
a26 1
while(push)
d31 1
d33 32
a64 2
printf(“enter data :\n”);
scanf(“%d”,&push->next->info);
d66 12
a77 1

d81 2
a82 2
int flag=0;
struct link *start,*new;
d86 1
a86 1
if(top==-1 && !flag)
d91 2
d96 1
d98 3
d102 1
a102 1
printf(“stack is full or stack create first\n”);
d105 10
d133 1
a133 1
printf(“____1.CREATE STACK__”);
@

1.3
log
@declear size
@
text
@d27 1
a27 1
printf(“enter data :\n”)
d40 1
a40 1
printf(“enter data :\n”)
@

1.2
log
@making the getchoice function and then creat_node function
create node funtion create the data space
and then push fucntion write the data in created space
@
text
@d4 1
a4 1
int stack_size;
d79 1
a79 1
scanf(“%d”,&stack_size);
@

1.1
log
@Initial revision
@
text
@d10 64
a73 1

d83 4
a86 3
printf(“____1.PUSH _____\n”);
printf(“____2.POP _____\n”);
printf(“____3.DISPLAY ____\n”);
d90 1
@

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>