-
Notifications
You must be signed in to change notification settings - Fork 0
/
listcmp.c
66 lines (61 loc) · 1.26 KB
/
listcmp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
char c;
struct node *next;
};
void printlist(struct node *start){
struct node *tmp = start;
printf("Printing link list\n");
while(tmp != NULL){
printf("%c->", tmp->c);
tmp = tmp->next;
}
printf("NULL\n");
}//printlist
struct node* getnewnode(char ch){
struct node *new = (struct node*)malloc(sizeof(struct node));
if(new){
new->c = ch;
new->next = NULL;
return new;
}
else{
printf("Can't allocate memory\n");
return;
}
}
struct node* createlist(char *str){
struct node *start = NULL, *newnode, *tmp;
int len = strlen(str);
int i;
printf("len=%d, str=%s\n", len, str);
for(i=0;i<len;i++){
newnode = getnewnode(str[i]);
if(start == NULL){
start = newnode;
}
else{
tmp = start;
while(tmp->next != NULL){
tmp = tmp->next;
}
tmp->next = newnode;
}
}//for
return start;
}//createlist
int main(void){
struct node *list1 = NULL;
struct node *list2 = NULL;
char str[100] = {0};
printf("Enter the string 1\n");
scanf("%s", &str);
list1 = createlist(str);
printlist(list1);
printf("Enter the string 2\n");
scanf("%s", &str);
list2 = createlist(str);
printlist(list2);
}//main