Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
struct Node {
int data;
};
new_node->data= new_data;
new_node->next= head;
head = new_node;
void display() {
ptr = head;
int main() {
clrscr();
insert(3);
insert(1);
insert(7);
insert(2);
insert(9);
display();
getch();
return 0;
#include<iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
struct node
int data;
node *next;
};
class list
private:
public:
list()
node *head=NULL;
node *tail=NULL;
temp->data=value;
temp->next=NULL;
if(head==NULL)
head=temp;
tail=temp;
temp=NULL;
}
else
tail->next=temp;
tail=temp;
void display()
temp=head;
while (temp!=NULL)
printf ("%d\t",temp->data);
temp=temp->next;
temp->data=value;
temp->next=head;
head=temp;
cur=head;
for(int i=1;i<pos;i++)
{
pre=cur;
cur=cur->next;
temp->data=value;
pre->next=temp;
temp->next=cur;
void delete_first()
temp=head;
head=head->next;
delete temp;
void delete_last()
current=head;
while(current->next!=NULL)
previous=current;
current=current->next;
tail=previous;
previous->next=NULL;
delete current;
{
node *current=new node;
current=head;
for(int i=1;i<pos;i++)
previous=current;
current=current->next;
previous->next=current->next;
};
int main()
clrscr();
list obj;
obj.createnode(25);
obj.createnode(50);
obj.createnode(90);
obj.createnode(40);
printf("\n--------------------------------------------------\n");
obj.display();
cout<<"\n-----------------Inserting At End------------------\n";
obj.createnode(55);
obj.display();
cout<<"\n----------------Inserting At Start----------------\n";
obj.insert_start(50);
obj.display();
cout<<"\n-------------Inserting At Particular--------------\n";
obj.insert_position(5,60);
obj.display();
cout<<"\n----------------Deleting At Start-----------------\n";
obj.delete_first();
obj.display();
cout<<"\n-----------------Deleting At End-------------------\n";
obj.delete_last();
obj.display();
cout<<"\n--------------Deleting At Particular--------------\n";
obj.delete_position(4);
obj.display();
cout<<"\n--------------------------------------------------\n";
system ("pause");
return 0;
Fig. 2 is a linked list program that displays all the numbers and then inserts
a number at the start, end and at the particular position of the original set
of numbers. This program also deletes number at the start, end and at
particular position.
LINKED LIST PROGRAM NO. 3
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct node {
int num;
}*stnode;
int main(){
int n;
printf("------------------------------------------------\n");
createNodeList(n);
displayList();
getch();
return 0;
int num, i;
else{
scanf("%d", &num);
stnode->num=num;
stnode->nextptr = NULL;
tmp= stnode;
for (i=2;i<=n;i++){
if(fnNode==NULL){
break;
else {
scanf("%d", &num);
fnNode->num = num;
fnNode->nextptr = NULL;
tmp->nextptr = fnNode;
tmp = tmp->nextptr;
void displayList(){
struct node *tmp;
if (stnode==NULL){
printf("List is empty.");
else{
tmp=stnode;
while (tmp!=NULL){
tmp = tmp->nextptr;
Fig. 3 lets the user to input the number of nodes and also the data for
the nodes. This program also displays all the numbers inputted by the
user.