CAN ANYONE DRAW ME A FLOWCHART FOR THIS
CODE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct studentname {
char letter[1];
struct studentname *next;
};
typedef struct studentname STUDENTName;
typedef STUDENTName *STUDENTNamePtr;
void printlist(STUDENTNamePtr startptr) //print
fucntion
{
STUDENTNamePtr crntptr;
crntptr=startptr;
printf("Print my last name in alphabetical
order\n");
while(crntptr!=NULL)
{
printf(" %s
->",crntptr->letter);
crntptr=crntptr->next;
}
printf("NULL");
}
int main()
{
// creating pointer pointer for node
STUDENTNamePtr startptr=NULL;
STUDENTNamePtr newptr;
STUDENTNamePtr crntptr;
// Create a linked list manually base on my last
name: NEFAT
newptr=(STUDENTName*)malloc(sizeof(STUDENTName));
strcpy(newptr->letter,"n");
newptr->next=NULL;
startptr=newptr;//assign startptr to
newptr
newptr=(STUDENTName*)malloc(sizeof(STUDENTName));
strcpy(newptr->letter,"e");
newptr->next=NULL;
startptr->next=newptr; //connect the first
node to newptr node
crntptr=newptr; // assign current pointer to
this node
newptr=(STUDENTName*)malloc(sizeof(STUDENTName));
strcpy(newptr->letter,"f");
newptr->next=NULL;
crntptr->next=newptr; //connect the last node
to newptr node
crntptr=newptr; // assign current pointer to
this node
newptr=(STUDENTName*)malloc(sizeof(STUDENTName));
strcpy(newptr->letter,"a");
newptr->next=NULL;
crntptr->next=newptr; //connect the last node
to newptr node
crntptr=newptr; // assign current pointer to
this node
newptr=(STUDENTName*)malloc(sizeof(STUDENTName));
strcpy(newptr->letter,"t");
newptr->next=NULL;
crntptr->next=newptr; //connect the last node
to newptr node
crntptr=newptr; // assign current pointer to
this node
printlist(startptr); //using the print
function
}
CAN ANYONE DRAW ME A FLOWCHART FOR THIS CODE. #include #include #include struct studentn
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am