Skip to content

Commit a4927bb

Browse files
Add files via upload
1 parent 8521bee commit a4927bb

7 files changed

+845
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
4+
typedef struct st{
5+
int info;
6+
struct st *link;
7+
}Node;
8+
9+
Node *start1=NULL;
10+
Node *start2=NULL;
11+
Node *start3=NULL;
12+
13+
void add_end(int value, int p){
14+
Node *newptr=NULL, *ptr;
15+
newptr=(Node*)malloc(sizeof(Node));
16+
newptr->info=value;
17+
newptr->link=NULL;
18+
if(p==1){
19+
if(start1==NULL){
20+
start1=newptr;
21+
}
22+
else{
23+
ptr=start1;
24+
while(ptr->link!=NULL){
25+
ptr=ptr->link;
26+
}
27+
ptr->link=newptr;
28+
}
29+
}
30+
else if(p==2){
31+
if(start2==NULL){
32+
start2=newptr;
33+
}
34+
else{
35+
ptr=start2;
36+
while(ptr->link!=NULL){
37+
ptr=ptr->link;
38+
}
39+
ptr->link=newptr;
40+
}
41+
}
42+
}
43+
44+
void display(Node *start){
45+
Node *ptr=start;
46+
while(ptr){
47+
printf("%d->", ptr->info);
48+
ptr=ptr->link;
49+
}
50+
printf("NULL\n");
51+
}
52+
53+
void add_to_list(int value){
54+
Node *newptr=NULL, *ptr;
55+
newptr=(Node*)malloc(sizeof(Node));
56+
newptr->info=value;
57+
newptr->link=NULL;
58+
if(start3==NULL){
59+
start3=newptr;
60+
}
61+
else{
62+
ptr=start3;
63+
while(ptr->link!=NULL){
64+
ptr=ptr->link;
65+
}
66+
ptr->link=newptr;
67+
}
68+
}
69+
70+
void adding(){
71+
Node *ptr1=start1, *ptr2=start2;
72+
int s=0;
73+
int c=0, value;
74+
while(ptr1 && ptr2){
75+
value=ptr1->info+ptr2->info+c;
76+
c=value/10;
77+
add_to_list(value%10);
78+
ptr1=ptr1->link;
79+
ptr2=ptr2->link;
80+
}
81+
while(ptr1){
82+
value=ptr1->info+c;
83+
c=value/10;
84+
add_to_list(value%10);
85+
ptr1=ptr1->link;
86+
}
87+
while(ptr2){
88+
value=ptr2->info+c;
89+
c=value/10;
90+
add_to_list(value%10);
91+
ptr2=ptr2->link;
92+
}
93+
}
94+
95+
96+
int main(){
97+
char choice;
98+
int num, choose, p=0;
99+
printf("Enter the details for first list: \n");
100+
while(1){
101+
printf("Do you want to Enter? y/n? ");
102+
scanf(" %c", &choice);
103+
if(choice=='y' || choice=='Y'){
104+
printf("Enter num to add: ");
105+
scanf("%d", &num);
106+
p=1;
107+
add_end(num, p);
108+
fflush(stdin);
109+
}
110+
else{
111+
break;
112+
}
113+
printf("\n1ST LINKED LIST:\t");
114+
display(start1);
115+
}
116+
printf("\n1ST LINKED LIST:\t");
117+
display(start1);
118+
119+
printf("\nEnter the details for second list: \n");
120+
while(1){
121+
printf("Do you want to Enter? y/n? ");
122+
scanf(" %c", &choice);
123+
if(choice=='y' || choice=='Y'){
124+
printf("Enter num to add: ");
125+
scanf("%d", &num);
126+
p=2;
127+
add_end(num, p);
128+
fflush(stdin);
129+
}
130+
else{
131+
break;
132+
}
133+
printf("\n2ND LINKED LIST:\t");
134+
display(start2);
135+
}
136+
printf("\n2ND LINKED LIST:\t");
137+
display(start2);
138+
139+
printf("\nSo, now two linked lists are:\n");
140+
display(start1);
141+
display(start2);
142+
143+
adding();
144+
printf("Add of two list is: ");
145+
display(start3);
146+
147+
return 0;
148+
}

LINKED LIST/CLL_By_DLL.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
4+
typedef struct st{
5+
struct st* lptr;
6+
int info;
7+
struct st* rptr;
8+
}Node;
9+
10+
Node *start=NULL;
11+
12+
void add(int value){
13+
Node *newptr=NULL, *ptr;
14+
newptr=(Node*)malloc(sizeof(Node));
15+
newptr->info=value;
16+
newptr->rptr=newptr->lptr=NULL;
17+
if(start==NULL){
18+
start=newptr;
19+
}
20+
else{
21+
ptr=start;
22+
while(ptr->rptr!=NULL){
23+
ptr=ptr->rptr;
24+
}
25+
ptr->rptr=newptr;
26+
newptr->lptr=ptr;
27+
newptr->rptr=start;
28+
start->lptr=newptr;
29+
}
30+
}
31+
32+
void display(){
33+
Node *ptr, *sptr;
34+
ptr=start;
35+
sptr=ptr->rptr;
36+
while(ptr->rptr!=start){
37+
printf("%d<->", ptr->info);
38+
ptr=ptr->rptr;
39+
}
40+
printf("NULL\n");
41+
}
42+
43+
int main(){
44+
char choice;
45+
int count=0, value;
46+
while(1){
47+
printf("do you want to insert or not? y/n? ");
48+
scanf(" %c", &choice);
49+
if(choice=='y' || choice=='Y'){
50+
printf("Enter number: ");
51+
scanf("%d", &value);
52+
add(value);
53+
}
54+
else{
55+
break;
56+
}
57+
}
58+
printf("\nLINKED LIST:\t");
59+
display();
60+
return 0;
61+
}

LINKED LIST/CLL_By_SLL.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//CLL by SLL
2+
3+
#include<stdio.h>
4+
#include<stdlib.h>
5+
6+
typedef struct st{
7+
int info;
8+
struct st* link;
9+
}Node;
10+
11+
Node *start=NULL;
12+
13+
void add_end(int value){
14+
Node *newptr=NULL, *ptr;
15+
newptr=(Node*)malloc(sizeof(Node));
16+
newptr->info=value;
17+
newptr->link=NULL;
18+
if(start==NULL){
19+
start=newptr;
20+
}
21+
else{
22+
ptr=start;
23+
while(ptr->link!=NULL){
24+
ptr=ptr->link;
25+
}
26+
ptr->link=newptr;
27+
newptr->link=start;
28+
}
29+
}
30+
31+
void display(){
32+
Node *ptr=start;
33+
// do{
34+
// printf("%d->", ptr->info);
35+
// ptr=ptr->link;
36+
// }while(ptr!=start);
37+
while(ptr->link!=start){
38+
printf("%d->", ptr->info);
39+
ptr=ptr->link;
40+
}
41+
}
42+
43+
int main(){
44+
int num;
45+
char choice;
46+
while(1){
47+
printf("Do you want to Enter? y/n?");
48+
scanf(" %c", &choice);
49+
if(choice=='y' || choice=='Y'){
50+
printf("Enter num: ");
51+
scanf("%d", &num);
52+
add_end(num);
53+
}
54+
else{
55+
break;
56+
}
57+
printf("CIRCULAR LINKED LIST:\t");
58+
display();
59+
}
60+
printf("CIRCULAR LINKED LIST:\t");
61+
display();
62+
return 0;
63+
}

0 commit comments

Comments
 (0)