singly link list deletion Algorithm
On the other hand, since simple associated lists by themselves do not let random access to the data or any form of efficient indexing, many basic operations — such as obtaining the last node of the list, finding a node that contains a given datum, or locating the place where a new node should be inserted — may necessitate iterate through most or all of the list components. They can be used to implement several other common abstract data types, including lists, stacks, queues, associative arrays, and S-expressions, though it is not uncommon to implement those data structures directly without use a associated list as the basis.
The problem of machine translation for natural language processing led Victor Yngve at Massachusetts Institute of technology (MIT) to use associated lists as data structures in his COMIT programming language for computer research in the field of linguistics. Several operating systems developed by Technical system adviser (originally of West Lafayette Indiana, and later of Chapel Hill, North Carolina) used singly associated lists as file structures. The now-classic diagram consisting of blocks representing list nodes with arrows indicating to successive list nodes looks in" program the logic theory machine" by Newell and Shaw in Proc.
/*Includes structure for a node which can be use to make new nodes of the Linked List.
It is assumed that the data in nodes will be an integer, though
function can be modified according to the data type, easily.
deleteNode deletes a node when passed with a key of the node.
*/
#include<stdio.h>
struct node
{int info;
struct node *link;
};
struct node *start=NULL;
///////////////////////////////////////////////////////////
struct node * createnode()//function to create node
{
struct node *t;
t=(struct node*)malloc(sizeof(struct node));
return(t);
}
////////////////////////////////////////////////////////
void insert()//function to insert at first location
{
struct node *p;
p=createnode();
printf("\nenter the number to insert");
scanf("%d",&p->info);
p->link=NULL;
if(start==NULL)
{
start=p;
}
else
{
p->link=start;
start=p;
}
}
///////////////////////////////////////////////////////////
void deletion()//function to delete from first position
{
struct node *t;
if(start==NULL)
{
printf("\nlist is empty");
}
else
{
struct node *p;
p=start;
start=start->link;
free(p);
}
}
///////////////////////////////////////////////////////
void viewlist()//function to display values
{
struct node *p;
if(start==NULL)
{
printf("\nlist is empty");
}
else
{ p=start;
while(p!=NULL)
{
printf("%d ",p->info);
p=p->link;
}
}
}
//////////////////////////////////////////////////////////////////////
int main()
{
int n;
while(1)
{
printf("\n1.add value at first location");
printf("\n2.delete value from first location");
printf("\n3.view value");
printf("\nenter your choice");
scanf("%d",&n);
switch(n)
{
case 1:
insert();
break;
case 2:
deletion();
break;
case 3:
viewlist();
break;
default:
printf("\ninvalid choice");
}
}
return(0);
}