#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node
{
int n;
struct node *ptr;
};
int main(void)
{
struct node *n1,*strt,*temp;
char a;
int cnt=0,i=0;
//char a[50],temp[100],line[100],word[50],e[50],final[100];
//FILE *fp,*fp1,*fp2;
strt=malloc(sizeof(struct node));
strt->n=90;
strt->ptr=NULL;
for(a='y';a!='n';)
{
n1=malloc(sizeof(struct node));
n1->n=++cnt;
n1->ptr=strt;
strt=n1;
scanf("%c",&a);
}
// ptr[1]=40;
// ptr[2]=30;
n1=strt;
while(n1!=NULL)
{ printf("\n %d at loc %p",n1->n,n1);
printf(" locaa %p \n",n1->ptr);
n1=n1->ptr;
}
return 0;
}
~
~
~
//implementation of doubly linked list.
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
void addnode();
void traverse();
struct node *new(int);
struct node
{
int info;
struct node *prev;
struct node *next;
};
//typedef struct node z;
struct node *start,*p,*temp;
void main()
{
int a,ch;
clrscr();
while(ch!=0)
{
printf("Enter the number");
scanf("%d",&a);
p=new(a);
addnode(p);
printf("press 1 for continue and 0 for end");
scanf("%d",&ch);
}
printf("your list is as follows");
traverse(start);
getch();
}
struct node *new(int a)
{
//start=p;
p=(struct node*)malloc(sizeof(struct node));
p->info=a;
p->prev=0;
p->next=0;
return p;
}
void addnode()
{
temp=start;
if(start==0)
{
start=p;
}
else
{
while(temp->next!=0)
temp=temp->next;
temp->next=p;
p->prev=temp;
}
}
void traverse()
{
temp=start;
while(temp!=0)
{
printf("%d",temp->info);
temp=temp->next;
}
}
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
void create();
void insert();
void delet();
void display();
struct node
{
int data;
struct node *link;
};
struct node *first=NULL,*last=NULL,*next,*prev,*cur;
void create()
{
cur=(struct node*)malloc(sizeof(struct node));
printf("\nENTER THE DATA: ");
scanf("%d",&cur->data);
cur->link=NULL;
first=cur;
last=cur;
}
void insert()
{
int pos,c=1;
cur=(struct node*)malloc(sizeof(struct node));
printf("\nENTER THE DATA: ");
scanf("%d",&cur->data);
printf("\nENTER THE POSITION: ");
scanf("%d",&pos);
if((pos==1) &&(first!=NULL))
{
cur->link = first;
first=cur;
}
else
{
next=first;
while(c<pos)
{
prev=next;
next=prev->link;
c++;
}
if(prev==NULL)
{
printf("\nINVALID POSITION\n");
}
else
{
cur->link=prev->link;
prev->link=cur;
}
}
}
void delet()
{
int pos,c=1;
printf("\nENTER THE POSITION : ");
scanf("%d",&pos);
if(first==NULL)
{
printf("\nLIST IS EMPTY\n");
}
else if(pos==1 && first->link==NULL)
{
printf("\n DELETED ELEMENT IS %d\n",first->data);
free(first);
first=NULL;
}
else if(pos==1 && first->link!=NULL)
{
cur=first;
first=first->link;
cur->link=NULL;
printf("\n DELETED ELEMENT IS %d\n",cur->data);
free(cur);
}
else
{
next=first;
while(c<pos)
{
cur=next;
next=next->link;
c++;
}
cur->link=next->link;
next->link=NULL;
if(next==NULL)
{
printf("\nINVALID POSITION\n");
}
else
{
printf("\n DELETED ELEMENT IS %d\n",next->data);
free(next);
}
}
}
void display()
{
cur=first;
while(cur!=NULL)
{
printf("\n %d",cur->data);
cur=cur->link;
}
}
void main()
{
int ch;
clrscr();
printf("\n\nSINGLY LINKED LIST");
do
{
printf("\n\n1.CREATE\n2.INSERT\n3.DELETE\n4.EXIT");
printf("\n\nENTER YOUR CHOICE : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
create();
display();
break;
case 2:
insert();
display();
break;
case 3:
delet();
display();
break;
case 4:
exit(0);
default:
printf("Invalid choice...");
}
}while(1);
}
What is linked list? Write a program to represent a linked list in C.
Linked list is a great advantage over array & the both are just opposite.So why don't you check out the problem properly.
In C programming, a double linked-list refers to a linked data structure that contains a set of links that have been linked sequentially.
Which of the following data structures can be randomly accessed giving loc?A. linked list implemented using arrayB. singly linked listC. double linked listD. both single and double linked listThe answer is A.
void pointer
Use a linked-list.
write a program which reads names of students and their telephones from a file and produce a linked list ordered in alphabetical order by the surname of the student.
#include<iostream.h>
write a c program to circular queue
You'll need to use a doubly-linked circular list, since otherwise when you pop off the tail element you'll need to whizz all the way round the list to find its predecessor. See the links section for an implementation of a doubly-linked circular list.
In C programming, a double linked-list refers to a linked data structure that contains a set of links that have been linked sequentially.
list any six consteations
for all datastructure ,c,c++ programs just visit codingdatastructure.blogspot.com and found on blog archive..
Not in C, no.
sorry
A linked list is a collection of items, often nodes, that are sequentially linked by some kind of index or pointer contained within each item.
Which of the following data structures can be randomly accessed giving loc?A. linked list implemented using arrayB. singly linked listC. double linked listD. both single and double linked listThe answer is A.
yes
A node is an object in some kind of linked structure, such as a linked list or tree. Nodes can be allocated off of the free list and added to the linked list or tree at hand, and then filled in with the data needed to represent some piece of information. Conversely, they can be unlinked from the linked list or tree, and then returned to the free list when they are no longer needed. Often, there is no direct variable of pointer in the program's scope that represents the node; rather, the node can be found by traversing a list of linkages, list or tree, in the applicable data structure. There are other definitions of "node", but this is the most common.