初学数据结构,求助实验C语言程序,请附带尽量详细说明,十分感激!
#include
#include
#include
#include
#defineM100
typedefstruct
chardata[M];
intlen;
}sqstring;
voidAssign(sqstring&s,chart[])
inti=0;
while(t[i]!=\0)
s.data[i]=t[i];
s.len=i;
voidDispstr(sqstrings)
inti;
for(i=0;i
cout<
cout<
intslength(sqstrings)
return(s.len);
strcopy(sqstrings,sqstring&t)
inti,j;
for(i=3,j=0;i
t.data[j]=s.data[i];
t.len=j;
return(1);
sqstringconcat(sqstrings,sqstringt)
sqstringr;
inti,j;
for(i=0;i
r.data[i]=s.data[i];
for(j=0;j
r.data[s.len+j]=t.data[j];
r.len=i+j;
return(r);
main()
cout<<"(1)建立串s,s1";
sqstrings,s1,s2,s3;
chart[]="abcdefghijklmn";
chard[]="XYZ";
Assign(s,t);
Assign(s1,d);
cout<
cout<<"(2)输出串s:";
Dispstr(s);
cout<
cout<<"(3)输出串s的长度:";
cout<
cout<
cout<<"(4)输出串s1:";
Dispstr(s1);
cout<
cout<<"(5)输出串s1的长度:";
cout<
cout<
cout<<"(6)提取串s中从第3个字符开始的4个字符而产生串s2:";
strcopy(s,s2);
cout<
cout<
cout<<"(7)输出串s2:";
Dispstr(s2);
cout<<"(8)将串s1和串s2连接起来而产生串s3:";
s3=concat(s1,s2);
cout<
cout<<"(9)输出串s3:";
Dispstr(s3);
cout<
本回答由网友推荐
数据结构编程求救
#include
#include
usingnamespacestd;
structList
intnum;
List*next;
List*head=NULL;
List*CreateList()
List*pL;
List*pEnd;
pL=newList;
head=pL;
pEnd=pL;
cout<<"请输入节点的数目,以0结束"<
cin>>pL->num;
while(pL->num!=0)
pEnd->next=pL;
pEnd=pL;
pL=newList;
cin>>pL->num;
deletepL;
pEnd->next=NULL;
returnhead;
voidShowList(List*head)
cout<
cout<<"链表节点如下:"<
while(head)
cout<num<
head=head->next;
voidInsertList(List*head,intnum)
List*list=newList;
List*l;
while(head)
l=head;
head=head->next;
list->num=num;
list->next=NULL;
l->next=list;
voidDeleteList(List*head,intnum)
List*l;
if(head->num==num)
l=head;
head=head->next;
::head=head;
deletel;
return;
List*l1=head;
while(head)
if(head->next==NULL){
cout<<"找不到不要删除的数字."<
return;
if(head->next->num==num)
l=head->next;
head->next=l->next;
deletel;
::head=l1;
cout<<"操作成功"<
return;
head=head->next;
cout<<"找不到不要删除的数字."<
intGetListNum(List*head)
intnum=0;
while(head)
num++;
head=head->next;
returnnum;
intmain()
stringstr;
begin:
cout<<"1->增加链表2->显示链表3->插入节点4->删除节点5->节点数目"<
cin>>str;
if(str[0]==1)
CreateList();
elseif(str[0]==2)
if(head==NULL)
cout<<"你的链表现在是空的,请增加链表"<
getchar();
getchar();
system("cls");
gotobegin;
ShowList(head);
elseif(str[0]==3)
if(head==NULL)
cout<<"你的链表现在是空的,请增加链表"<
getchar();
getchar();
system("cls");
gotobegin;
intnum;
cout<<"请输入要插入的数字:"<
cin>>num;
InsertList(head,num);
elseif(str[0]==4)
if(head==NULL)
cout<<"你的链表现在是空的,请增加链表"<
getchar();
getchar();
system("cls");
gotobegin;
intnum;
cout<<"请输入要删除的数字:"<
cin>>num;
DeleteList(head,num);
elseif(str[0]==5)
cout<<"节点数是:"<
cout<<"输入错误,请重新输入.";
if(str[0]!=Q&&str[0]!=q){
cout<
getchar();
getchar();
system("cls");
gotobegin;
#include
#include
usingnamespacestd;
structStack{
charc;
Stack*pNext;
voidInitStack(Stack*&s)
s=NULL;
charPeek(Stack*s)
if(s==NULL){
cout<<"栈是空的."<
return-1;
returns->c;
voidPush(Stack*&s,Stack*newS)
newS->pNext=s;
s=newS;
charPop(Stack*&s)
if(s==NULL)
cout<<"栈是空的."<
return-1;
Stack*pNext;
charc;
if(s)
pNext=s->pNext;
c=s->c;
deletes;
s=pNext;
returnc;
intmain()
Stack*s;
Stack*s1;
InitStack(s);
longnum;
intm;
intk;
charc;
cout<<"输入一个数:"<
cin>>num;
cout<<"输入要转换的进制:"<
cin>>k;
while(num!=0)
m=num%k;
c=(int(0)+m);
s1=newStack;
s1->c=c;
Push(s,s1);
num/=k;
while(s)
cout<
cout<
本回答由网友推荐